<template>
  <div>
    <el-table :data="memberList">
      <el-table-column
        fixed="left"
        prop="id"
        label="ID"
        min-width="60"
      ></el-table-column>
      <el-table-column label="头像" min-width="180">
        <template v-slot="props">
          <img
            :src="$baseUrl + props.row.avatarurl"
            style="height: 80px"
            alt=""
          />
        </template>
      </el-table-column>
      <el-table-column
        prop="phone"
        label="用户名"
        min-width="180"
      ></el-table-column>
      <el-table-column
        prop="nickname"
        label="昵称"
        min-width="180"
      ></el-table-column>
      <el-table-column label="性别" min-width="180">
        <template v-slot="props">
          {{ props.row.sex === 1 ? "男" : "女" }}
        </template>
      </el-table-column>
      <el-table-column
        prop="region"
        label="地址"
        min-width="180"
      ></el-table-column>
      <el-table-column
        prop="profession"
        label="职业"
        min-width="180"
      ></el-table-column>
      <el-table-column label="注册时间" min-width="180">
        <template v-slot="props">
          {{ props.row.addtime | dateFmt }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" min-width="180">
        <template v-slot="props">
          <el-button
            type="success"
            size="mini"
            round
            plain
            v-if="props.row.status === 1"
            >正常</el-button
          >
          <el-button type="danger" size="mini" round plain v-else
            >禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="160" fixed="right">
        <template v-slot="props">
          <el-button
            @click="edit(props.row)"
            type="primary"
            size="mini"
            round
            plain
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      @current-change="pageChange"
      :total="memberTotal"
      :page-size="size"
      layout="total,prev,pager,next,jumper"
    ></el-pagination>
    <!-- 调用对话框组件 -->
    <Dialog ref="dialog" :info="info" @memberUpdate="memberUpdateHandle" />
  </div>
</template>

<script>
// 导入对话框组件
import Dialog from "./Dialog";
// 导入vuex辅助函数
import { mapState, mapActions } from "vuex";
export default {
  components: { Dialog },
  data() {
    return {
      info: {
        isShow: false,
      },
      page: 1,
      size: 5,
    };
  },
  computed: {
    ...mapState("member", ["memberList", "memberTotal"]),
  },
  methods: {
    ...mapActions("member", ["getMemberListAction", "getMemberTotalAction"]),
    // 自定义事件memberUpdate处理函数
    memberUpdateHandle() {
      // 请求会员列表
      this.getMemberListAction({ page: this.page, size: this.size });
      // 请求会员总数
      this.getMemberTotalAction();
    },
    // 编辑按钮点击事件处理函数
    edit(row) {
      // 1-显示对话框
      this.info.isShow = true;
      // 2-将会员信息传递给对话框组件
      this.$refs.dialog.setFormData(row);
    },
    // 分页按钮点击事件处理函数
    pageChange(page) {
      // 1-更新页码值
      this.page = page;
      // 2-根据最新的页码请求数据
      this.getMemberListAction({ page: this.page, size: this.size });
    },
  },
  created() {
    this.memberUpdateHandle();
  },
};
</script>

<style>
</style>